package com.bdqn;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Short1 {
    private static JedisPool jedisPool;

    static {
        JedisPoolConfig config=new JedisPoolConfig();
        config.setMaxTotal(50);
        config.setMaxIdle(10);
        config.setMinIdle(7);
        config.setMaxWaitMillis(1000);
        config.setTestOnBorrow(true);

        jedisPool = new JedisPool(
                config,
                "192.168.1.101",
                6379,
                10000,
                "123456",
                0
        );
    }
    public void destroy(){
        if (!(jedisPool==null)||jedisPool.isClosed()) {
            jedisPool.close();
        }
    }
    public Boolean exists(String key){
        Jedis jedis=jedisPool.getResource();
        Boolean bool=jedis.exists(key);
        jedis.close();
        return bool;
    }

    public Long time(String key,int dataTime){
        Jedis jedis=jedisPool.getResource();
        Long shi=null;
        try {
            jedis.expire(key,dataTime);
            shi=new Long(1);
        } catch (Exception e) {
            shi=new Long(0);
            e.printStackTrace();
        }
        jedis.close();
        return shi;
    }

    public Long ttl(String key){
        Jedis jedis=jedisPool.getResource();
        Long result=jedis.ttl(key);
        jedis.close();
        return result;
    }
}
